package com.yonyou.pmclouds.basecom.bp.processor;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.exception.DataReferencedException;
import com.yonyou.pmclouds.basecom.ref.itf.ReferenceChecker;
import com.yonyou.pmclouds.basecom.util.BeanHelper;

public class BdReferenceChecker<T> implements SingleProcessor<T> {
    private String refCode;
    private ReferenceChecker checker;

    public BdReferenceChecker(String bdRefCode, ReferenceChecker checker) {
        this.refCode = bdRefCode;
        this.checker = checker;
    }

    @Override
    public void process(T vo, T orig) throws BusinessException {
        if (checker.checkReferenced(refCode, new String[]{BeanHelper.getId(vo)})) {
            throw new DataReferencedException();
        }
    }
}
